﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    UserRoles
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="CurrentMenuIDContent" runat="server" >configMenu</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <script src="<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>" type="text/javascript"></script>
    <script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="../../Content/jquery-ui-1.8.16.custom.css" />
    <script type="text/javascript" src="../../Scripts/jquery-ui-1.8.16.custom.min.js"></script>
    <script type="text/javascript" src="../../Scripts/site.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.tablesorter.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.tablesorter.pager.js"></script>
    <script src="<%= Url.Content("~/Scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <table>
        <tr>
            <td>
                <h2>
                    Security Roles</h2>
            </td>
            <td>
                <input type="submit" class="button" value="Create" onclick="javascript:createRole(); return false;" />
            </td>
        </tr>
        <tr>
            <td id="roleListContent">
                <% Html.RenderPartial("~/Views/Role/Controls/RoleGrid.ascx", ViewData("Roles"))%>
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td>
                <%  Using (Ajax.BeginForm("SaveRole", New AjaxOptions With {.UpdateTargetId = "roleListContent", .OnBegin = "formValidate", .OnSuccess = "cancel"}))%>
                <div id="roleDetailContent">
                    &nbsp
                </div>
                <% End Using%>
            </td>
            <td>
            </td>
        </tr>
    </table>
    <% Html.RenderPartial("~/Views/History/Controls/History.ascx")%>
    <script type="text/javascript">
        var selectedRoleID = 0;

        function createRole() {
            jQuery.ajax({
                type: 'GET',
                url: '<%= Html.AttributeEncode(Url.Action("RoleDetail/0")) %>',
                success: function (result) {
                    $('#roleDetailContent').html(result).removeClass("hidden");
                }
            });
        }

        function selectRole(id, siteID) {
            jQuery.ajax({
                type: 'GET',
                url: '<%= Html.AttributeEncode(Url.Action("RoleDetail/")) %>' + id,
                success: function (result) {
                    $('#roleDetailContent').html(result).removeClass("hidden");
                }
            });
        }

        function saveRole() {
            if (formValidate() === true) {
                alert('ok');
                var desc = $("#roleName").val();
                var siteID = $("#Site").val();
                jQuery.ajax({
                    type: 'POST',
                    data: { siteID: siteID, id: selectedRoleID, desc: desc },
                    url: '<%= Html.AttributeEncode(Url.Action("SaveRole")) %>',
                    success: function (result) {
                        $('#roleListContent').html(result);
                    }
                });
                $("#roleDetailContent").addClass("hidden");
            }
        }

        function cancel() {
            $("#roleDetailContent").addClass("hidden");
        }

        function formValidate() {
            return $('form').validate({
                rules: {
                    "roleName": { required: true }
                },
                messages: {
                    "roleName": "Role name is required."
                }
            }).form();
        }

    </script>
</asp:Content>

